package com.libinshen.wxpay.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * //Mybatis-plus 自动帮助完成实体字段与 数据库字段之间的驼峰转换关系
 */
@Configuration
@EnableSwagger2
public class Swagger2Config {

    com.google.common.base.Predicate<RequestHandler> selector1 = RequestHandlerSelectors.basePackage("com.libinshen.wxpay.videoAliBaBa.controller");
    com.google.common.base.Predicate<RequestHandler> selector2 = RequestHandlerSelectors.basePackage("com.libinshen.wxpay.login.controller");
    com.google.common.base.Predicate<RequestHandler> selector3 = RequestHandlerSelectors.basePackage("com.libinshen.wxpay.OSSAliYun.controller");
    com.google.common.base.Predicate<RequestHandler> selector4 = RequestHandlerSelectors.basePackage("com.libinshen.wxpay.payAli.controller");
    com.google.common.base.Predicate<RequestHandler> selector5 = RequestHandlerSelectors.basePackage("com.libinshen.wxpay.payV3Wx.controller");
    com.google.common.base.Predicate<RequestHandler> selector6 = RequestHandlerSelectors.basePackage("com.libinshen.wxpay.quartz.controller");

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("自研金牛系统")
                .apiInfo(apiInfo())
                .select()
                //包下的类，生成接口文档
                .apis(Predicates.or(selector1, selector2, selector3, selector4, selector5, selector6))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("李彬燊后台管理系统")
                .description("libinshen自研系统文档")
                .termsOfServiceUrl("https://www.renren.io")
                .version("4.0.0")
                .build();
    }
}
